package net.kts.attraction.search;


import java.util.ArrayList;
import java.util.List;


import net.kts.attraction.AttractionMap;
import net.kts.attraction.search.model.Address;
import net.kts.attraction.subway.SubwayListActivity;
import net.kts.attraction.subway.SubwaySearchMap;
import net.kts.attraction.subway.adapter.AttractionUserSelectAdapter;
import net.kts.define.KTSString;
import net.kts.help.HelpLayout;
import net.kts.help.HelpPreferences;
import net.kts.help.HelpService;
import net.kts.main.R;
import net.kts.transrate.TranslateService;
import net.kts.util.network.NetworkCheck;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class AttractionUserSelect extends Activity{

	private OnItemClickListener onItemClickListener = null;
	private ListView listView = null;
	private Address address = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.attraction_userselect_list);
		
		itemClickInit();
		getIntentInit();
		
		this.listView = (ListView)findViewById(R.id.userSelectList);
		this.listView.setOnItemClickListener(onItemClickListener);
		
		userSelectListInit();
		
		if(HelpPreferences.isShowing())
	        new HelpService(this)
	        		.add(new HelpLayout(R.drawable.help_search));
		
	}
	
	private void userSelectListInit() {
		ArrayAdapter<String> adapterList = null;
		List<String> strList = new ArrayList<String>();
		
//		strList.add(TranslateService.translate(KTSString.currentToTarget));
//		strList.add(TranslateService.translate(KTSString.currentToSubway));
//		strList.add(TranslateService.translate(KTSString.subwayGuide));
		
		strList.add(TranslateService.translateRepository(KTSString.Current) + "->" + TranslateService.translateRepository(KTSString.Target));
		strList.add(TranslateService.translateRepository(KTSString.Current) + "->" + TranslateService.translateRepository(KTSString.Subway));
		strList.add(TranslateService.translateRepository(KTSString.SubwayGuide));
		
		adapterList = new AttractionUserSelectAdapter(this,  R.layout.attraction_userselect_list, strList);
		listView.setAdapter(adapterList);
		
	}
	
	

	private void getIntentInit() {
		 Intent intent = getIntent();
		 
		 Bundle bundle = intent.getExtras();
		 this.address = (Address)bundle.get("address");
		 
//		 address = new Address();
//		 address.setAddressFullName(intent.getStringExtra("name"));
//		 address.setCity(intent.getStringExtra("city"));
//		 address.setLatitude(intent.getStringExtra("lat"));
//		 address.setLongitude(intent.getStringExtra("lng"));
		
	}

	private void itemClickInit() {
		this.onItemClickListener = new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> items, View v, int position,
					long id) {
				// TODO Auto-generated method stub
				
				Class targetClass = null;
				
				// target
				if(position == 0) {
					targetClass = AttractionMap.class;
				}
				// subway
				else if(position == 1) {
					targetClass = SubwaySearchMap.class;
				}
				// subway guide
				else {
					targetClass = SubwayListActivity.class;
				}
				
				Intent intent = new Intent(getBaseContext(), targetClass);
				
				Bundle bundle = new Bundle();
				bundle.putSerializable("address", address);
				intent.putExtras(bundle);
				
				startActivity(intent);
				
			}
		};
		
	}
	
	
}
